package api

import (
	"gitee.com/hexug/vblog/tree/master/api/apps"
	"gitee.com/hexug/vblog/tree/master/api/apps/post"
	"gitee.com/hexug/vblog/tree/master/api/middleware"
	"github.com/gin-gonic/gin"
)

type PostApi struct {
	Svc post.Server
}

func (a *PostApi) RegisterRouter(i gin.IRouter) {
	//获取文章详情
	i.GET("/:id", a.GetDetailPost)
	//获取文章列表
	i.GET("/", a.GetListPosts)

	//加入认证的中间件
	i.Use(middleware.MidAuth)
	//创建文章
	i.POST("/", a.CreatePost)
	//完全更新文章
	i.PUT("/:id", a.UpdatePost)
	//不更新零值
	i.PATCH("/:id", a.UpdatePost)
	//删除文章
	i.DELETE("/:id", a.DeletePost)
}

func (a *PostApi) Name() string {
	return post.AppName
}

func (a *PostApi) Init() error {
	a.Svc = apps.GetApp(a.Name()).(post.Server)
	return nil
}

func init() {
	apps.RegisterApi(&PostApi{})
}
